package com.kzd.btgame.app

import android.content.Context
import com.kzd.btgame.BuildConfig
import com.module.lemlin.http.HttpServiceFactory
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig
import rxhttp.RxHttpPlugins

const val SDK_UM_APP_KEY = ""

const val SDK_WX_APP_ID = ""

const val SDK_QQ_APP_ID = ""

/**
 * 初始化友盟sdk
 * */
fun initUMSDK(context: Context) {
    //设置友盟log开关
    UMConfigure.setLogEnabled(true)
    //友盟预初始化
    UMConfigure.preInit(context, SDK_UM_APP_KEY, SPSConstance.channel)
    //是否已同意隐私协议
    if (SPSConstance.isReadAgree == false)
        return
    //友盟正式初始化
    UMConfigure.init(context, SDK_UM_APP_KEY, SPSConstance.channel, UMConfigure.DEVICE_TYPE_PHONE, null)
    // 微信设置
    PlatformConfig.setWeixin(SDK_WX_APP_ID, "84a7555beb12ef494cdbc9f9aea13238")
    PlatformConfig.setWXFileProvider("com.kzd.btgame.fileProvider")
    // QQ设置
    PlatformConfig.setQQZone(SDK_QQ_APP_ID, "c82893c735c5bea095790ff03a8ff16d")
    PlatformConfig.setQQFileProvider("com.kzd.btgame.fileProvider")
}

/**
 * 初始化RxHttp
 * */
fun initRxHttp(context: Context) {
    RxHttpPlugins.init(
        HttpServiceFactory.client().build()
    ).setOnParamAssembly {
        val packageInfo = context.packageManager
            .getPackageInfo(context.packageName, 0)
        it.addHeader("ua", System.getProperty("http.agent")?.run {
            substring(indexOf("("), indexOf(")") + 1)
        })
        it.addHeader("version", packageInfo.packageName)
        it.addHeader("channel", SPSConstance.channel)
        it.add("member_id", SPSConstance.memberId)
        it.add("uid", SPSConstance.uid)
    }.setDebug(true)
}